<template>
  <div>
      <el-link
        type="primary"
        icon="el-icon-time"
        style="font-size: 20px;margin-left: 20px;"
        @click="showHistory"
      ></el-link>
    <el-dialog title="历史修改记录" :visible.sync="formVisible">
      <el-table
        :data="recordList"
        tooltip-effect="light"
        style="width: 100%"
        size="mini"
      >
        <el-table-column  prop="fileUrl" min-width="140%" label="文件名">
        </el-table-column>
        <el-table-column prop="cuser" label="修改人"  >
          <template slot-scope="scope">
            {{ userMap[scope.row.cuser] }}
          </template>
        </el-table-column>
        <el-table-column  prop="cdate" label="修改时间">
        </el-table-column>
        <el-table-column  label="操作"  >
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              @click="showRecord(scope.row.fileUrl)"
            >预览</el-button
            >
            <el-button
              type="primary"
              size="mini"
              @click="exportRecord(scope.row.fileUrl)"
            >下载</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <!--<el-dialog
      :visible="showDoc "
      :show-close="true"
      :width="'80%'"
      class="dialog-div-pre-style"
      :before-close="closePreviewClick"
      center>
      <div v-if="showDoc" class="dialog-body-content-base-style">
        <iframe frameborder="0"
                :src="'https://view.officeapps.live.com/op/view.aspx?src=' + this.showFileUrl"
                width='100%'>
        </iframe>
      </div>
    </el-dialog>-->
  </div>
</template>

<script>
import { m } from "@/store/yg/common/local";
import { ajax } from "@/store/yg/common/utils";
import * as constant from "@/store/yg/common/constant";
export default {
  props: ["data"],
  data() {
    return {
      formVisible: false,
      recordList: [],
      userMap: {},
      showDoc: false,
      showFileUrl: '',
      templateId: '',
    };
  },
  mounted() {
  },
  methods: {
    showHistory(){
      this.formVisible = true;
      this.templateId = this.data.id;
      ajax("findByTemplateId", {"templateId":this.templateId})
        .then(res => {
          if (res.code == 200) {
              this.userMap = res.data2;
              this.recordList = res.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    showRecord(fileUrl) {
      this.showFileUrl = 'https://view.officeapps.live.com/op/view.aspx?src=' + constant.FILE_SERVER + fileUrl;
      window.open(this.showFileUrl, '_blank');
    },
    exportRecord(fileName) {
      window.open(constant.FILE_SERVER + fileName);
    },
  }
};
</script>

<style scoped></style>
